define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'luyougfen/index' + location.search,
                    add_url: 'luyougfen/add',
                    edit_url: 'luyougfen/edit',
                    del_url: 'luyougfen/del',
                    multi_url: 'luyougfen/multi',
                    import_url: 'luyougfen/import',
                    table: 'luyougfen',
                }
            });

            var table = $("#table");

            const columns = [
                {checkbox: true},
                {field: 'day', title: __('Day'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                {field: 'fen', title: __('分光器'),operate: false },
                {field: 'tiaoxian', title: __('黄色跳线'),operate: false },
                {field: 'pixian', title: __('30米皮纤'),operate: false },
                // {field: 'qi_yi', title: __('(分光器)易剑伟'),operate: false },
                // {field: 'qi_zhong', title: __('(分光器)钟明锋'),operate: false },
                // {field: 'qi_zhuo', title: __('(分光器)卓大旺'),operate: false },
                // {field: 'qi_wu', title: __('(分光器)伍海鹏'),operate: false },
                // {field: 'qi_yang', title: __('(分光器)杨宇航'),operate: false },
                // {field: 'tp_yi', title: __('(黄色跳线)易剑伟'),operate: false },
                // {field: 'tp_zhong', title: __('黄色跳线)钟明锋'),operate: false },
                // {field: 'tp_zhuo', title: __('(黄色跳线)卓大旺'),operate: false },
                // {field: 'tp_wu', title: __('(黄色跳线)伍海鹏'),operate: false },
                // {field: 'tp_yang', title: __('(黄色跳线)杨宇航'),operate: false },
                // {field: 'yi_yi', title: __('(30米皮纤)易剑伟'),operate: false },
                // {field: 'yi_zhong', title: __('(30米皮纤)钟明锋'),operate: false },
                // {field: 'yi_zhuo', title: __('(30米皮纤)卓大旺'),operate: false },
                // {field: 'yi_wu', title: __('(30米皮纤)伍海鹏'),operate: false },
                // {field: 'yi_yang', title: __('(30米皮纤)杨宇航'),operate: false },
            ]
            const typeMap = {fen: '分光器', tiaoxian: '黄色跳线', pixian: '30米皮纤'}
            for (const i in typeMap) {
                for (const empItem of empList) {
                    columns.push({field: `emp_${i}_${empItem.id}`, title: `(${typeMap[i]})${empItem.name}`, operate: false })
                }
            }
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,
                showToggle: false,
                showColumns: false,
                searchFormVisible: true,
                columns: [columns]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
            Table.api.fixedheader(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
